package com.yy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yy.mapper.RestaurantMapper;
import com.yy.pojo.Restaurant;
import com.yy.service.RestaurantService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author yyu
 * @description 针对表【t_restaurant】的数据库操作Service实现
 * @createDate 2023-12-22 16:16:12
 */
@Service
public class RestaurantServiceImpl extends ServiceImpl<RestaurantMapper, Restaurant>
        implements RestaurantService {

    @Autowired
    private RestaurantMapper restaurantMapper;


    @Override
    public IPage<Restaurant> getRestaurantList(int pageNum, int pageSize, Restaurant restaurant) {
        IPage<Restaurant> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Restaurant> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        if (StringUtils.isNotEmpty(restaurant.getRestaurantName())) {
            lambdaQueryWrapper.like(Restaurant::getRestaurantName,restaurant.getRestaurantName());
        }
        if (StringUtils.isNotEmpty(restaurant.getRestaurantLocation())) {
            lambdaQueryWrapper.like(Restaurant::getRestaurantLocation,restaurant.getRestaurantLocation());
        }

        if (StringUtils.isNotEmpty(restaurant.getStatus())) {
            lambdaQueryWrapper.eq(Restaurant::getStatus,restaurant.getStatus());
        }

        restaurantMapper.selectPage(page, lambdaQueryWrapper);

        return page;
    }
}



